<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('新增稿件')" />
	<th:block th:include="include :: layout-latest-css" />
	<link th:href="@{/css/cms/cms.css}" rel="stylesheet"/>
</head>
<body class="gray-bg">
	
	<div class="ui-layout-north">
		<div class="ui-layout-content white-bg" style="overflow-x: hidden;border-bottom: 1px solid #d2d2d2;">
			<div class="ui-cms-document-icon col-sm-1">
				<i class="fa fa-desktop fa-2x" aria-hidden="true"></i>
			</div>
			<div class="ui-cms-document-btn col-sm-11">
				<a class="btn btn-sm btn-primary" onclick="submitHandler()">保存</a>
				<a class="btn btn-sm btn-default" onclick="closeItem()">关闭</a>
			</div>
		</div>
	</div>

	<form class="form-horizontal m" id="form-docuemnt-add">
	<!-- 表单开始 -->
	<div class="ui-layout-west">
		
	</div>
	
	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 white-bg">
					<div class="form-group" style="margin: 10px auto;">	
						<label class="col-sm-2 control-label">标&nbsp;&nbsp;&nbsp;&nbsp;题：</label>
						<div class="col-sm-10 input-group">
							<input name="title" class="form-control" type="text" maxlength="100" required>
							<span class="input-group-addon ui-cms-words-count">0 / 100</span>
						</div>
					</div>
					<div class="form-group" style="margin: 10px auto;">	
						<label class="col-sm-2 control-label">副标题：</label>
						<div class="col-sm-10 input-group">
							<input name="subtitle" class="form-control" type="text" maxlength="100">
							<span class="input-group-addon ui-cms-words-count">0 / 100</span>
						</div>
					</div>
					<div class="form-group">	
						<div class="col-sm-12">
						    <script id="editor" type="text/plain" style="width:100%;margin: 0 auto;"></script>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<!-- 操作栏 -->
	<div class="ui-layout-east">
		<div class="ui-layout-content white-bg" style="overflow-x: hidden;">
			<div class="row">
				<div class="col-sm-12">
					<!-- 防止重复提交 -->
		        	<input type="hidden" name="token" th:value="${session.token}"/>
		        	<div class="form-group">	
						<label class="col-sm-3 control-label">站点名称：</label>
						<div class="col-sm-9">
							<input type="hidden" name="siteId" th:value="${channel.siteId}" />
							<input name=siteName class="form-control" th:value="${channel.siteName}" type="text" readonly="readonly" required="required">
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">栏目名称：</label>
						<div class="col-sm-9">
							<input type="hidden" name="channelId" th:value="${channel.id}"/>
							<input name=channelName class="form-control" th:value="${channel.channelName}" type="text" readonly="readonly" required="required">
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">文档类型：</label>
						<div class="col-sm-9">
							<div class="radio-box" th:each="dict : ${@dict.getDict('cms_document_type')}">
								<input type="radio" th:id="${dict.id}" name="docType" th:value="${dict.dictValue}" th:checked="${dict.isDefault == 'Y'}">
								<label th:for="${dict.id}" th:text="${dict.dictName}"></label>
							</div>
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">文档摘要：</label>
						<div class="col-sm-9">
							<textarea name="docAbstract" maxlength="500" placeholder="请填写文档摘要" class="form-control" rows="3"></textarea>
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">关键字：</label>
						<div class="col-sm-9">
							<textarea name="docKeywords" maxlength="500" placeholder="请填写关键字" class="form-control" rows="3"></textarea>
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">文档作者：</label>
						<div class="col-sm-9">
							<input name="docAuthor" placeholder="请填写文档作者" th:value="${user.userName}" class="form-control" type="text" required="required">
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">撰写时间：</label>
						<div class="col-sm-9 select-time">
							<input name="writeTime" class="form-control time-input" placeholder="yyyy-MM-dd HH:mm:ss" type="text" readonly="readonly" required="required">
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">原文地址：</label>
						<div class="col-sm-9 select-time">
							<textarea name="originalHttpUrl" maxlength="500" placeholder="请填写原文链接地址http(s)://" class="form-control" rows="3"></textarea>
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">显示顺序：</label>
						<div class="col-sm-9">
							<input name="orderNum" class="form-control" placeholder="填写值越小越越置顶" type="number">
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">稿件状态：</label>
						<div class="col-sm-9">
							<select name="docStatus" class="form-control m-b" th:with="type=${@dict.getDict('cms_document_status')}">
				                <option th:each="dict : ${type}" th:text="${dict.dictName}" th:value="${dict.dictValue}"></option>
				            </select>
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">数据状态：</label>
						<div class="col-sm-9">
							<div class="radio-box" th:each="dict : ${@dict.getDict('sys_data_status')}">
								<input type="radio" th:id="${dict.id}" name="status" th:value="${dict.dictValue}" th:checked="${dict.isDefault == 'Y'}">
								<label th:for="${dict.id}" th:text="${dict.dictName}"></label>
							</div>
						</div>
					</div>
					<div class="form-group">	
						<label class="col-sm-3 control-label">备注：</label>
						<div class="col-sm-9">
							<textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<!-- 表单结束 -->
	</form>
	
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: ueditor-js" />
	<script th:inline="javascript">
		
		var prefix = ctx + "cms/document";
		
		$(function() {
		    var panehHidden = false;
		    if ($(this).width() < 769) {
		        panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: 450, north__closable: false, east__size: 450 });
		    
		    $('input[name="writeTime"]').val(dateFormat('yyyy-MM-dd HH:mm:ss', new Date()));
		    
		    $('input[name="title"]').bind('input propertychange', function() {
				$(this).parent().find('.ui-cms-words-count').html($(this).val().length + ' / 100');
			});
			$('input[name="subtitle"]').bind('input propertychange', function() {
				$(this).parent().find('.ui-cms-words-count').html($(this).val().length + ' / 100');
			});
		});
		
		var ue = UE.getEditor('editor',{
			serverUrl: ctx + 'easyfile/ueditor',
			initialStyle: 'body{font-size:16px;line-height:1.2;font-family:默认字体;}',
			catchRemoteImageEnable: false
		});
		
		ue.ready(function(){
			//初始化编辑器自适应高度
			setTimeout(function() {
				var eduid = $('#editor').find('div:first-child').attr('id');
				var height = ($(window).height() - 300) + 'px';
				$('#' + eduid + '_iframeholder').css({'height' : height});
			}, 500);
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
				//不是iframe页面
				if(self == top){
					$.operate.save(prefix + "/add", $('#form-docuemnt-add').serialize());
				}else{
					$.operate.saveTab(prefix + "/add", $('#form-docuemnt-add').serialize());
				}
	        }
	    }

	</script>
</body>
</html>